package com.jing.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jing.mapper.UserLogMapper;
import com.jing.pojo.PageBean;
import com.jing.pojo.UserReservationInfo;
import com.jing.service.UserLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 陈书憬
 * @version 1.0
 * 2024/9/24
 */
@Service
public class UserLogServiceImpl implements UserLogService {

    @Autowired
    private UserLogMapper userLogMapper;

    @Override
    public List<UserReservationInfo> getRoomNames(Integer userId) {
        List<UserReservationInfo> userReservationInfos = userLogMapper.getRoomNames(userId);
        System.out.println("userId="+userId);
        System.out.println("aaasasdasdasdsa"+userReservationInfos);
        return userReservationInfos;
    }

    @Override
    public PageBean<UserReservationInfo> getUserLogList(Integer pageNum, Integer pageSize, Integer userId, String names, String state) {
        //1.创建PageBean对象
        PageBean<UserReservationInfo> pb = new PageBean<>();

        //2.开启分页查询 PageHelper
        PageHelper.startPage(pageNum, pageSize);

        List<UserReservationInfo> as = userLogMapper.getUserLogList(userId, names, state);
        //Page中提供了方法,可以获取PageHelper分页查询后 得到的总记录条数和当前页数据
        Page<UserReservationInfo> p = (Page<UserReservationInfo>) as;

        //把数据填充到PageBean对象中
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }

    @Override
    public PageBean<UserReservationInfo> getAllList(Integer pageNum, Integer pageSize, String names, String state) {
        //1.创建PageBean对象
        PageBean<UserReservationInfo> pb = new PageBean<>();

        //2.开启分页查询 PageHelper
        PageHelper.startPage(pageNum, pageSize);

        List<UserReservationInfo> as = userLogMapper.getAllUserLogList( names, state);
        //Page中提供了方法,可以获取PageHelper分页查询后 得到的总记录条数和当前页数据
        Page<UserReservationInfo> p = (Page<UserReservationInfo>) as;

        //把数据填充到PageBean对象中
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }
}
